#include <QDebug>
#include "WindowingTool.h"
#include "ui_WindowingTool.h"

WindowingTool::WindowingTool(QWidget *parent) :
	QWidget(parent),
	ui(new Ui::WindowingTool)
{
	ui->setupUi(this);

	connect(ui->sldWidth, SIGNAL(valueChanged(int)), this, SLOT(SlotWindowing()));
	connect(ui->sldCenter, SIGNAL(valueChanged(int)), this, SLOT(SlotWindowing()));
}

WindowingTool::~WindowingTool()
{
	delete ui;
}

void WindowingTool::SlotSetControl(int iMax, int iMin, int iWidth, int iCenter)
{
	disconnect(ui->sldWidth, SIGNAL(valueChanged(int)), this, SLOT(SlotWindowing()));
	disconnect(ui->sldCenter, SIGNAL(valueChanged(int)), this, SLOT(SlotWindowing()));
	ui->sldWidth->setMaximum(iMax - iMin);
	ui->sldCenter->setMaximum(iMax);
	ui->sldCenter->setMinimum(iMin);
	ui->sldWidth->setValue(iWidth);
	ui->sldCenter->setValue(iCenter);
	connect(ui->sldWidth, SIGNAL(valueChanged(int)), this, SLOT(SlotWindowing()));
	connect(ui->sldCenter, SIGNAL(valueChanged(int)), this, SLOT(SlotWindowing()));
	this->SlotWindowing();
}

void WindowingTool::SlotWindowing()
{
	qDebug() << "[windowing]" << ui->sldWidth->value() << ui->sldCenter->value();
	emit SignalWindowing(ui->sldWidth->value(), ui->sldCenter->value());
}

void WindowingTool::SlotReset()
{
	ui->sldWidth->setValue(ui->sldWidth->maximum());
	ui->sldCenter->setValue((ui->sldCenter->maximum() - ui->sldCenter->minimum()) / 2 + ui->sldCenter->minimum());
	qDebug() << "[windowing reset]" << ui->sldWidth->value() << ui->sldCenter->value();
	this->SlotWindowing(); //최초 강제 windowing 호출
}
